package com.supor.aiot.basket.api;

import com.android.baseconfig.base.BaseApiResult;
import com.android.baseconfig.base.BaseRetrofit;
import com.android.baseconfig.base.DataApiResult;
import com.supor.aiot.basket.bean.AddBasketBean;
import com.supor.aiot.basket.bean.BasketRequestBean;
import com.supor.aiot.basket.bean.BuyedIngredientsBean;
import com.supor.aiot.basket.bean.IngredientBean;
import com.supor.aiot.basket.bean.IngredientBuyBean;
import com.supor.aiot.basket.bean.IngredientDetailBean;
import com.supor.aiot.basket.bean.IngredientListBean;
import com.supor.aiot.basket.bean.MakeIngredientBean;

import java.util.List;

import io.reactivex.rxjava3.core.Observable;

/**
 * ---------------------------------------------------------------- <br>
 * Copyright (C) 2014-2020, by het, Shenzhen, All rights reserved.  <br>
 * ---------------------------------------------------------------- <br>
 * <p>
 * 描述: UserImpl <br>
 * 作者: lei <br>
 * 日期: 2020/11/7 <br>
 */
public class BasketImpl extends BaseRetrofit<BasketService> implements BasketService {
    private static BasketImpl instance;

    public static BasketImpl getInstance() {
        if (instance == null) {
            instance = new BasketImpl();
        }
        return instance;
    }

    /**
     * 分页查询菜篮子接口
     * @return BaseApiResult<String>
     */
    @Override
    public Observable<BaseApiResult<DataApiResult<List<IngredientBean>>>> requestBasket(int page, int limit) {
        return api.requestBasket(page,limit).compose(this.applySchedulers());
    }

    /**
     * 添加到菜篮子接口
     * @return BaseApiResult<String>
     */
    @Override
    public Observable<BaseApiResult<String>> addIntoBasket(AddBasketBean basketBean) {
        return api.addIntoBasket(basketBean).compose(this.applySchedulers());
    }

    /**
     *  删除单个菜篮子接口
     * @return BaseApiResult<DataApiResult<List<IpsBean>>>>>
     */
    @Override
    public Observable<BaseApiResult<String>> deleteBasket(String ids) {
        return api.deleteBasket(ids).compose(this.applySchedulers());
    }

    /**
     * 清除菜篮子接口
     * @param ipsBean ipsBean
     * @return BaseApiResult<String>
     */
    public Observable<BaseApiResult<String>> cleanBasket(BasketRequestBean ipsBean) {
        return api.cleanBasket(ipsBean).compose(this.applySchedulers());
    }

    /**
     * 获取菜篮子食材
     * @return
     */
    @Override
    public Observable<BaseApiResult<BuyedIngredientsBean>> getIngredients(String ids) {
        return api.getIngredients(ids).compose(this.applySchedulers());
    }

    /**
     *  查询用户下清单列表
     * @return BaseApiResult<DataApiResult<List<IpsBean>>>>>
     */
    @Override
    public Observable<BaseApiResult<DataApiResult<List<IngredientListBean>>>> checkIngredientList() {
        return api.checkIngredientList().compose(this.applySchedulers());
    }

    /**
     * 生成食材清单
     */
    @Override
    public Observable<BaseApiResult<MakeIngredientBean>> makeIngredientList(String recipeID) {
        return api.makeIngredientList(recipeID).compose(this.applySchedulers());
    }

    /**
     * 获取食材清单详情
     * @param recipeID
     * @return
     */
    @Override
    public Observable<BaseApiResult<IngredientDetailBean>> getIngredientDetail(String recipeID) {
        return api.getIngredientDetail(recipeID).compose(this.applySchedulers());
    }

    /**
     *  根据菜篮子ID全部选中/不选中食材
     * @return BaseApiResult<String>
     */
    @Override
    public Observable<BaseApiResult<String>> selectAllIngredient(String recipeID, int state) {
        return api.selectAllIngredient(recipeID,state).compose(this.applySchedulers());
    }

    /**
     *  根据食材ID修改状态
     * @return BaseApiResult<String>
     */
    @Override
    public Observable<BaseApiResult<String>> changeIngredientState(String ingredientID, int state) {
        return api.changeIngredientState(ingredientID,state).compose(this.applySchedulers());
    }

    /**
     *  根据食材ID修改数量
     * @return BaseApiResult<String>
     */
    @Override
    public Observable<BaseApiResult<String>> changeIngredientState(String ingredientID,String number) {
        return api.changeIngredientState(ingredientID,number).compose(this.applySchedulers());
    }

    /**
     *  根据单个食材ID修改购买状态
     * @return BaseApiResult<String>
     */
    @Override
    public Observable<BaseApiResult<String>> changeIngredientBuy(IngredientBuyBean buyBean) {
        return api.changeIngredientBuy(buyBean).compose(this.applySchedulers());
    }

    /**
     *  根据清单ID修改购买状态
     * @return BaseApiResult<String>
     */
    @Override
    public Observable<BaseApiResult<String>> changeIngredientListBuy(String batchno, int state) {
        return api.changeIngredientListBuy(batchno,state).compose(this.applySchedulers());
    }

    /**
     *  删除清单
     * @return BaseApiResult<String>
     */
    @Override
    public Observable<BaseApiResult<String>> deleteIngredientList(String ids) {
        return api.deleteIngredientList(ids).compose(this.applySchedulers());
    }

    /**
     * 获取分享清单链接
     * @param recipeId
     * @param type
     * @return
     */
    @Override
    public Observable<BaseApiResult<String>> getSharedIngredient(String recipeId, int type) {
        return api.getSharedIngredient(recipeId,type).compose(this.applySchedulers());
    }

}
